<?php 
	Zend_Loader::loadClass("SelectListModel");
	$data_count = $this->data_count;
	$page = $this->page;
	$line_per_page = $this->line_per_page;
	$search_link = $this->search_link;
	
	$list_line_per_page = SelectListModel::getListLinePerPage();
	$page_count = ceil($data_count / $line_per_page);
	$display_page = 5;
	
	
	$display_mode = 0;
	//process paging		
	if($page == 1){
		for($i=1; $i <= $display_page && $i <= $page_count; $i++)
			$display_pages[] = $i;
		$display_mode = 1;
		
	}else if($page == $page_count){
		for($i = $page_count,$k=0; $i > 0 && $k < 5; $i--,$k++)
			$display_pages[] = $i;
		$display_pages = array_reverse($display_pages);
		$display_mode = 2;
		
	}else{
		if($page < ceil($display_page / 2)){
			$min_page = 1;
			$max_page = $page_count < $display_page ? $page_count : $display_page;
			
		}else if($page > $page_count - floor($display_page/2) && $page < $page_count){
			$max_page = $page_count;
			$min_page = $page_count - $display_page > 0 ? $page_count - $display_page + 1 : 1;
			 
		}else{
			$min_page = $page - floor($display_page/2);
			$max_page = $page + floor($display_page/2);
		}
		
		for($i = $min_page; $i <= $max_page; $i++){
			$display_pages[] = $i;
		}
	}
?>

<div class="tablePager">
	<div class="linesPerPage">
		<?php echo $this->translate("Line per page")?>
		<?php echo $this->formSelect('line_per_page', $line_per_page, NULL, $list_line_per_page)?>
	</div>
	<?php if($data_count > 0):?>
	<div class="pageList">
		<?php if($display_mode == 2 || $display_mode == 0):?>
			<span class="pagingItem">
				<a href="" onclick="doChangePage(1);return false">
					<?php echo $this->translate('First')?>
				</a>
			</span>

			<span class="pagingItem">
				<a href="" onclick="doChangePage(<?php echo $page - 1 > 0 ? $page - 1 : $page?>);return false;">
					<?php echo $this->translate('Previous')?>
				</a>
			</span>	
		<?php endif;?>
		
		<?php foreach($display_pages as $item):?>
			<span class="<?php echo $page == $item ? "pagingItemSelected" : "pagingItem"?>" >
				<a href="" onclick="doChangePage(<?php echo $item?>);return false;">
					<?php echo $item?>
				</a>
			</span>	
		<?php endforeach;?>
		
		<?php if($display_mode < 2):?>
			<span class="pagingItem">
				<a href="" onclick="doChangePage(<?php echo $page + 1 > $page_count ? $page : $page + 1?>);return false;">
					<?php echo $this->translate('Next')?>
				</a>
			</span>
			
			<span class="pagingItem">
				<a href="" onclick="doChangePage(<?php echo $page_count?>);return false;">
					<?php echo $this->translate('Last')?>
				</a>
			</span>	
		<?php endif;?>
		<span class="pagingItem">
			<?php if (($page * $line_per_page) > $data_count) :?>
			<?php echo $page * $line_per_page - $line_per_page + 1 . " - " . $data_count . " / " . $data_count?>
			<?php else :?>
			<?php echo $page * $line_per_page - $line_per_page + 1 . " - " . $page * $line_per_page . " / " . $data_count?>
			<?php endif;?>
		</span>
	</div>
	<?php endif;?>
</div>
<?php echo $this->formHidden("page", $page)?>